<?php
class Model_Admin_SysLog extends Model{
    public function getInfo($type,$start_date,$end_date,$offset,$rows){

        $query= DB::select(array(DB::expr('count(1)'), 'total'))

        ->from('syslog')

        ->where("type",'like',"%$type%");

        if(!empty($start_date)){

            $query=$query->and_where("createdon",">=",$start_date);
        }

        if(!empty($end_date)){

            $query=$query->and_where("createdon","<=",$end_date);

        }

        $total=$query->execute()->get("total");

        $whereSql="where t.type like '%$type%' and t.isdeleted<>'1' ";

        if(!empty($start_date)){

            $whereSql=$whereSql." and t.createdon>='$start_date'";
        }

        if(!empty($end_date)){

            $whereSql=$whereSql." and t.createdon<='$end_date'";

        }
        
        $sql="select t.syslogid id,t.type,t.description,s.user_email,t.createdon
             from syslog t 
             left join site_user s on s.site_userid=t.userid
             ".$whereSql."
             order by t.CreatedOn desc
             limit $offset,$rows";

         $data=DB::query(Database::SELECT,$sql)->execute()->as_array();

         return array("total"=>$total,"rows"=>$data);
    }
}